package com.qiaofang.collectmanage.facade.impl;

import com.qiaofang.collectmanage.service.OperatorLogService;
import com.qiaofang.collectmanage.stub.bean.OperatorLogDTO;
import com.qiaofang.collectmanage.stub.bean.SearchOperatorLogPageAndCountDTO;
import com.qiaofang.collectmanage.stub.bean.SearchOperatorLogPageDTO;
import com.qiaofang.collectmanage.stub.constants.OperatorLogResponseCode;
import com.qiaofang.collectmanage.stub.facade.OperatorLogFacade;
import com.qiaofang.collectmanage.stub.request.*;
import com.qiaofang.collectmanage.stub.response.*;
import com.qiaofang.common.constant.CommonResponseCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * Created by generator on 2018-8-1 20:37:55
 */
@RestController
public class OperatorLogFacadeImpl implements OperatorLogFacade {


    @Autowired
    private OperatorLogService operatorLogService;


    @Override
    public SaveOperatorLogResponse batchSaveOperatorLog(@RequestBody @Valid SaveOperatorLogRequest request) {
        SaveOperatorLogResponse response = new SaveOperatorLogResponse();
        int count = operatorLogService.saveOperatorLog(request.getSaveOperatorLogDTOs());
        if (count <= 0) {
            response.setResponseCode(OperatorLogResponseCode.RC_SAVE_ERROR.getResponseCode());
            response.setResponseMessage(OperatorLogResponseCode.RC_SAVE_ERROR.getResponseMessage());
        }
        return response;
    }

    @Override
    public SearchOperatorLogPageResponse searchOperatorLogPage(@RequestBody @Valid SearchOperatorLogPageRequest request) {
        SearchOperatorLogPageResponse response = new SearchOperatorLogPageResponse();
        SearchOperatorLogPageAndCountDTO searchOperatorLogPageAndCountDTO = operatorLogService.searchOperatorLogPageAndCount(request.getSearchOperatorLogPostDTO(), request.getPageDTO());
        SearchOperatorLogPageDTO searchOperatorLogPageDTO = new SearchOperatorLogPageDTO();
        searchOperatorLogPageDTO.setData(searchOperatorLogPageAndCountDTO.getList());
        searchOperatorLogPageDTO.setCount(searchOperatorLogPageAndCountDTO.getCount());
        response.setData(searchOperatorLogPageDTO);
        response.setResponseCode(CommonResponseCode.RC_SUCCESS.getResponseCode());
        response.setResponseMessage(CommonResponseCode.RC_SUCCESS.getResponseMessage());
        return response;
    }


}
